namespace _7 {

var reverse = function(x: number): number {
    if (x === 0) return 0
    var i = 0, 
        answer = 0, 
        reminder = Math.abs(x),
        sign = x / reminder 
    while (reminder !== 0) {
        answer *= 10
        answer += (reminder % 10)
        if (answer > Math.pow(2, 32)/2 ) return 0  
        i++
        reminder = Math.floor(reminder / 10) 
    }
    return answer * sign
};    

console.assert( reverse( 1534236469) === 0)
console.assert( reverse( 0) === 0)
console.assert( reverse( 123) === 321)
console.assert( reverse( -123) === -321)

}
